<link rel="stylesheet" type="text/css" href="<?= base_url() ?>file/js/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="<?= base_url() ?>file/js/easyui/themes/icon.css">

<script type="text/javascript" src="<?= base_url() ?>file/js/jquery-1.4.js"></script>
<!--<script type="text/javascript" src="<?= base_url() ?>file/js/add-item.js"></script>-->
	

		
<form id="form" action="<?=base_url() ?>returns/save" method="post">
	<div class="panel-wrap" style="height: auto">
		<div class="panel-header-div">Cluster Information</div>
		<div class="panel-body-div">
		
			<div class="left-panel-body">
				<?php foreach($cluster as $item):?>
					<h2><?php echo $item->territory_name?></h2>
					
				<?php endforeach?>
			</div>
			<div class="right-panel-body">
				<table class="table-right-panel" width="100%" border="solid black 1px">
					<tr align="center" class="tr-colour">
						<th width="50%" align="center">Date</th>
						<th align="center">Return No</th>
					</tr>
					
					
					<tr align="center" class="gray">
						<td class="readonly" width="50%" align="center">
							<input type="text" name="return_date"  id="date" readonly="true" value="<?php echo $return_date?>"/>	
						</td>
						
						<td class="readonly" width="50%" align="center">
							<input type="text" name="return_no"  id="return_no" disabled="true" value="<?php echo $returns_no?>"/>
						</td>
						
					</tr>
				</table>
			</div>
			
		</div>
	</div>


	<div class="panel-wrap" style="height: auto">
		<div class="panel-header-div">Return Information</div>
		
		<div class="panel-body-div">
			<div class="child-panel-body">
				<div class="left-panel-body">
				
					<table class="table-right-panel" width="80%" border="solid black 1px">
						<tr align="center" class="tr-colour2">
							<th width="40%" align="center">Sales Name</th>
							<th width="60%" align="center">Sales ID</th>
						</tr>
						
						
						<tr align="center" class="gray">
							<td>
								<input type="text" name="sales_id"  id="sales_id" readonly="true" value="<?php echo $sales_name?>"/>
							</td>
							<td class="readonly" align="center">
								<input type="text" name="sales_name" id="sales-name" size="40" disabled="true" value="<?php echo $sales_id?>"/>
							</td>
							
							
						</tr>
					</table>
				</div>
			</div>
			<div class="child-panel-body">
				<div class="left-panel-body">
				
					<table class="table-right-panel" width="80%" border="solid black 1px">
						<tr align="center" class="tr-colour2">
							<th width="40%" align="center">Outlet Name</th>
							<th width="60%" align="center">Outlet ID</th>
						</tr>
						
						
						<tr align="center" class="gray">
							<td>
								<input type="text" name="outlet_id"  id="outlet_id" readonly="true" value="<?php echo $outlet_name?>"/>
							</td>
							<td class="readonly" align="center">
								<input type="text" name="outlet_name" id="outlet-name" size="40" disabled="true" value="<?php echo $outlet_id?>"/>
							</td>
							
							
						</tr>
					</table>
				</div>
			
			</div>
			<br><br>
					
			<div class="child-panel-body">
					<h2>Return Products</h2>
					<table class="table-right-panel" id="table-updateable" width="92%" style="margin-left: 19px;">
						<tr align="center" class="tr-colour3" id="tr_select_all">
							<th width="30%">ICCID</th>
							<th width="15%">Buying Date</th>
							<th width="40%">Description</th>
							<th width="10%">Price (Rp.)</th>							
						</tr>
						<?php foreach($items as $item):?>
							<tr>
								<td><input type="text" size="30" readonly="true" value="<?php echo $item->iccid?>"/></td>
								<td class="readonly"><input type="text" readonly="true" id="buying<?php echo $item->iccid?>"/></td>
								<td><input type="text" readonly="true" size="50" id="name<?php echo $item->iccid?>"/></td>
								<td class="readonly"><input type="text" readonly="true" id="price<?php echo $item->iccid?>"/></td>
							</tr>
							
						<?php endforeach?>
						
					</table>
			</div>
			
			<div class="child-panel-body">
					<h2>Swap Products</h2>
					<table class="table-right-panel" id="table-updateable" width="92%" style="margin-left: 19px;">
						<tr align="center" class="tr-colour3" id="tr_select_all">
							<th width="20%">ICCID</th>
							<th width="20%">Item Code</th>
							<th width="40%">Item Name</th>
							<th width="20%">Item Group</th>							
						</tr>
						<?php foreach($swap as $item):?>
							<tr>
								<td><input type="text" readonly="true" size="30" value="<?php echo $item->iccid?>"/></td>
								<td class="readonly"><input type="text" size="25" readonly="true" value="<?php echo $item->item_code?>"/></td>
								<td><input type="text" readonly="true" size="60" value="<?php echo $item->item_name?>"/></td>
								<td class="readonly"><input type="text" size="20" readonly="true" value="<?php echo $item->item_group_name?>"/></td>
							</tr>
							
						<?php endforeach?>
						
					</table>
			</div>
		
			<div class="child-panel-body-2">
				<table class="table-right-panel" width="92%" style="margin-left: 19px; border: none; ">
					<tr style="height: 15px;">
						<td style="text-align: left; font-weight: bold; font-size: 1.3em;">Remark:</td>
						<td width="94%" style="border-bottom: solid #000 1px;">
							<textarea id="remark" rows="6" cols="130"><?php echo $remarks?></textarea>
							
						</td>
						
					</tr>
				</table>
			</div>
		
			
		</div>
	</div>
</form>

<script type="text/javascript">	
	var iccidname = new Array("N/A");
	var iccidbuying = new Array("N/A");
	var iccidprice = new Array("N/A");
	var nama = new Array("N/A");
	var price = new Array("N/A");
	var buying = new Array("N/A");
	var x = 1;
	var y = 1;
	var z = 1;
	
	<?php foreach($itemname as $item):?>
		iccidname[x] = "<?php echo $item->iccid?>";
		nama[x] = "<?php echo $item->item_name?>";
		x++;
	<?php endforeach?>
	
	<?php foreach($buyingdate as $item):?>
		iccidbuying[y] = "<?php echo $item->iccid?>";
		buying[y] = "<?php echo $item->created_on?>";
		y++;
	<?php endforeach?> 
	
	<?php foreach($itemprice as $item):?>
		iccidprice[z] = "<?php echo $item->iccid?>";
		price[z] = <?php echo $item->price?>;
		z++;
	<?php endforeach?>

	<?php foreach($items as $item):?>
		var iccid = "<?php echo $item->iccid?>";
		tes(iccid);
	<?php endforeach?>
		
	function tes(check) {
		var tampilname = 0;
		var x = iccidname.length;
		
		var tampilbuying = 0;
		var y = iccidbuying.length;
		
		var tampilprice = 0;
		var z = iccidprice.length;
		
		for(var i=1; i<=x; i++){
			if(iccidname[i] == check){
				tampilname = i;
				i=x+1;
			}
		}
		
		for(var i=1; i<=y; i++){
			if(iccidbuying[i] == check){
				tampilbuying = i;
				i=y+1;
			}
		}
		
		for(var i=1; i<=z; i++){
			if(iccidprice[i] == check){
				tampilprice = i;
				i=z+1;
			}
		}
		
		if(tampilname==0){
			//alert("Barang Sudah Di Return atau Barang Belum Terjual atau ICCID salah");
			//document.getElementById("nomorBarang["+index+"]").value = "";
			document.getElementById("buying"+check).value = "N/A";
			document.getElementById("name"+check).value = "N/A";
			document.getElementById("price"+check).value = "N/A";
		}
		else{
			document.getElementById("buying"+check).value = buying[tampilbuying];
			document.getElementById("name"+check).value = nama[tampilname];
			document.getElementById("price"+check).value = price[tampilprice];
		}
	}
</script>